print('=' * 20)
print("欢迎使用通讯录")
print("1.添加联系人")
print("2.删除联系人")
print("3.修改联系人")
print("4.查找联系人")
print("5.查看通讯录")
print("6.退出")
print("=" * 20)

person_info=[]

while True:
    n = int(input("请输入您要执行的指令:"))
    per_dict={}

    if  n == 1:#增加
         
        name=input("请输入联系人的姓名:")

        for i in person_info:
            if i.get('姓名') == name:
                print('您已经添加了该联系人！')
                break
        else:
            phone=input('请输入联系人的电话:')
            email=input('请输入联系人的邮箱:')
            address=input('请输入联系人的地址:')
            if phone.strip() == ' ' or email.strip() == ' ' or address.strip() == ' ':
                print('您的输入有误,请重新输入')
                continue
            else:
                per_dict.update({'姓名': name,
                                '手机号': phone,
                                '电子邮箱': email,
                                '联系地址': address})
                person_info.append(per_dict)
                print('保存成功！！') 
                continue  

    elif n == 2:#删除
        if len(person_info) == 0:
            print('通讯录无信息!')
        else :
            name=str(input("请输入您要删除的联系人:"))
            for i in person_info:
                if name in i.values():
                    person_info.remove(i)
                    print('删除成功！')
                    break
                else:
                    print("查无此人~")
                    break

    elif n == 3:#查找
        if len(person_info) != 0:
            name=input('请输入您要查找的联系人:')
            for i in person_info:
                if i.get('姓名')==name:
                    index_num=person_info.index(i)
                    for title, info in person_info[index_num].items():
                        print(title + ':' + info)
                    break
            else:
                print('查无此人,请重新查找。')
                continue
        else:
            print('通讯录无信息!')
            continue

    elif n == 4:#修改
        if len(person_info) == 0:
            print('通讯录无信息!')
            continue
        else:
            name = input('请输入您要修改的联系人姓名:')
            for i in person_info:
                if i.get('姓名')==name:
                    index_num = person_info.index(i)
                    dict_cur_perinfo = person_info[index_num]
                    for title, info in dict_cur_perinfo.items():
                        print(title + ':' + info)
                    modi_name = input('请输入新的姓名：')
                    modi_phone = input('请输入新的手机号：')
                    modi_email = input('请输入新的邮箱：')
                    modi_address = input('请输入新的地址：')
                    dict_cur_perinfo.update(姓名= modi_name)
                    dict_cur_perinfo.update(手机号= modi_phone)
                    dict_cur_perinfo.update(电子邮箱= modi_email)
                    dict_cur_perinfo.update(联系地址= modi_address)
                    print('修改成功！')
                    break
            else:
                print('查无此人,请重新查找。')
                continue

    elif n == 5:#查看
        if len(person_info) == 0:
            print('通讯录无信息!')
            continue
        for i in person_info:
            print('--*' * 6)
            for title, info in i.items():
                print(title + ':' + info)
            print('--*' * 6)

    elif n == 6:#结束
        print('您已退出 拜拜！')
        break

    else:
        print('您输入的指令错误,请重新输入:')
        continue